package util;


import java.util.HashMap;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Cleiton
 */
public class TabelaHost {

    private DefaultTableModel defaultTableModel;
    private JTable table;

    public TabelaHost(JTable table) {
        this.table = table;
        defaultTableModel = (DefaultTableModel) table.getModel();
    }

    /**
     * Limpa uma determinada Tabela;
     */
    public void limparTabela() {
        // defaultTableModel.fireTableRowsDeleted(0, defaultTableModel.getRowCount());
        for (int i = defaultTableModel.getRowCount(); i > 0; i--) {
            defaultTableModel.removeRow(0);
        }
    }

    public void adicionarHost(String nome) {
        Vector vector = new Vector();
        vector.add(nome);
        defaultTableModel.addRow(vector);

    }

    /**
     * Obtem a rede mapeada apartir da tabela
     * @return a rede completamente mapeada
     */
    public HashMap<String,String> getLigacaoGatways() {
        HashMap<String, String> hostGatWay= new HashMap<String, String>();
        for (int i = 0; i < defaultTableModel.getRowCount(); i++) {
            String host = (String) defaultTableModel.getValueAt(i, 0);
            String gatWay = (String) defaultTableModel.getValueAt(i, 1);
            hostGatWay.put(host, gatWay);
        }
        return hostGatWay;
    }
}
